package com.ys.fmms.exception;

import com.ys.fmms.util.Result;
import com.ys.fmms.util.ResultCodeEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalException {

    // 处理登录时账户名或密码错误异常
    @ExceptionHandler(value = LoginException.class)
    public Result handlerLoginException(Exception e) {
        e.printStackTrace();
        return Result.build(null, ResultCodeEnum.LOGIN_ERROR);
    }

    // 处理用户账户异常
    @ExceptionHandler(AccountException.class)
    public Result handlerAccountException(Exception e) {
        e.printStackTrace();
        return Result.build(null, ResultCodeEnum.ACCOUNT_ERROR);
    }

    // 处理统一异常 返回result对象
    @ExceptionHandler(Exception.class)
    public Result handlerException(Exception e) {
        e.printStackTrace();
        String s = e.getMessage();
        Result result = new Result();
        result.code(555).message(s);
        return result;
    }

    // 处理用户输入原始密码错误
    @ExceptionHandler(UserPasswordException.class)
    public Result handlerCheckPasswordException(Exception e){
        e.printStackTrace();
        return Result.build(null,ResultCodeEnum.CHECK_PASSWORD_ERROR);
    }
}
